package com.leyantech.ecp.agenx.connector.di;

import com.leyantech.chaos.kafka.KafkaProducerStringClient;
import com.leyantech.ecp.agenx.common.di.JWTAuthProvider;
import com.leyantech.ecp.agenx.common.sender.KafkaSender;
import com.leyantech.ecp.agenx.common.sender.Sender;

import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import com.google.inject.name.Names;
import io.vertx.ext.auth.jwt.JWTAuth;

/**
 * @author eahau, {@literal <eahau@foxmail.com>}
 * @date 2022-11-17.
 */
public class ConnectorModule extends AbstractModule {

  @Override
  protected void configure() {
    install(new FactoryModuleBuilder().build(WebSocketMessageHandlerFactory.class));

    bind(JWTAuth.class).toProvider(JWTAuthProvider.class).asEagerSingleton();

    bind(String.class).annotatedWith(Names.named("topicKey")).toInstance("connector.message.topic");

    bind(new TypeLiteral<Sender<String>>() {
    })
        .to(KafkaSender.class)
        .asEagerSingleton();

  }

  @Singleton
  @Provides
  public KafkaProducerStringClient provideKafkaProducerStringClient() {
    return KafkaProducerStringClient.newBuilder("connector").build();
  }

}
